import 'package:flutter/material.dart';
import 'package:stop/pages/cart/cart_page.dart';
import 'package:stop/pages/cate/cate_page.dart';
import 'package:stop/pages/home/home_page.dart';
import 'package:stop/pages/user/user_page.dart';





class TabBarPage extends StatefulWidget {
  const TabBarPage({ Key? key }) : super(key: key);

  @override
  TabBarPageState createState() => TabBarPageState();
}

  int _currentIndex = 0;

class TabBarPageState extends State<TabBarPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: [
          HomePage(),
          CatePage(),
          CartPage(),
          UserPage()
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        type:BottomNavigationBarType.fixed,//点击图标固定不动
        currentIndex: _currentIndex,//当前索引
        unselectedItemColor: Colors.black,
        selectedItemColor: Colors.red,
        onTap: (value){//点击事件
         setState(() {
            _currentIndex = value;
         });
        },
        items: barItemList(),
        ),
    );
  }


//  导航栏文字+图标
  List<BottomNavigationBarItem> barItemList(){
    List<BottomNavigationBarItem> items = [];
    items.add(
      BottomNavigationBarItem(
        label: "首页",
        icon:Image.asset(
          'tabbar/home.png',
          width: 24,
          height: 24,
        ),
        activeIcon: Image.asset(
          'tabbar/home-active.png',
          width: 24,
          height: 24,
          ),
      ),
    );
     items.add(
      BottomNavigationBarItem(
        label: "分类",
        icon:Image.asset(
          'tabbar/cate.png',
          width: 24,
          height: 24,
        ),
        activeIcon: Image.asset(
          'tabbar/cate-active.png',
          width: 24,
          height: 24,
          ),
      ),
    );
     items.add(
      BottomNavigationBarItem(
        label: "购物车",
        icon:Image.asset(
          'tabbar/cart.png',
          width: 24,
          height: 24,
        ),
        activeIcon: Image.asset(
          'tabbar/cart-active.png',
          width: 24,
          height: 24,
          ),
      ),
    );
     items.add(
      BottomNavigationBarItem(
        label: "我的",
        icon:Image.asset(
          'tabbar/user.png',
          width: 24,
          height: 24,
        ),
        activeIcon: Image.asset(
          'tabbar/user-active.png',
          width: 24,
          height: 24,
          ),
      ),
    );
    return items;
}

}

